﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiYiTong.Rocket.Helper;

namespace YiYiTong.Rocket.DataAccess
{
    /// <summary>
    /// 数据库配置类 
    /// 根据配置环境来确定哪个数据库连接
    /// </summary>
    public class DBConfig
    {
        #region Instance
        private DBConfig()
        {
        }
        private static DBConfig _instance;

        private static object _syncObject = new object();

        public static DBConfig Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_syncObject)
                    {
                        if (_instance == null)
                        {
                            _instance = new DBConfig();
                            string env = ConfigHelper.AppSetting<string>("environment");
                            switch (env)
                            {
                                case "fat": //测试环境
                                    _instance.strApiDBConn = "FatApiDBConnStr";
                                    _instance.strAdminDBConn = "FatAdminDBConnStr";
                                    break;
                                case "prd": //生产环境
                                    _instance.strApiDBConn = "PrdApiDBConnStr";
                                    _instance.strAdminDBConn = "PrdAdminDBConnStr";
                                    break;
                                default:
                                    //默认开发环境
                                    _instance.strApiDBConn = "DevApiDBConnStr";
                                    _instance.strAdminDBConn = "DevAdminDBConnStr";
                                    break;
                            }
                        }
                    }
                }
                return _instance;
            }
        }
        #endregion

        public string strApiDBConn { get; set; }


        public string strAdminDBConn { get; set; }
    }
}
